package samples
{
	import by.blooddy.crypto.serialization.JSON;
	import com.google.maps.LatLng;
	import com.google.maps.Map;
	import com.google.maps.MapEvent;
	import com.google.maps.overlays.Marker;
	import com.google.maps.overlays.MarkerOptions;
	
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	
	import marcel.debug.*;
	import marcel.display.View;
	import marcel.display.gui.buttons.SimpleTextButton;
	import marcel.external.facebook.data.FBPlace;
	
	public class GoogleMapSample extends View
	{
		protected var map:Map = new Map();
		
		public function GoogleMapSample()
		{
			super(100,100, ORIENTATION_VERTICAL);
			_initMap();
			
			//--------------------------------------------------------------------------
			//
			//  !!! Add map_1_19a.swc to the project
			//
			//--------------------------------------------------------------------------
		}
	
		protected function onClick(e:MouseEvent):void {
			switch (e.currentTarget.data){
				case "place" :
					
					var place:String = '{';
					place += '"id": "120342051353159",';
					place += '	"name": "Publicis Net",';
					place += '"picture": "http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs222.ash2/50232_120342051353159_9855_s.jpg",';
					place += '"link": "http://www.facebook.com/pages/Paris-France/Publicis-Net/120342051353159",',
					place += '"category": "Local business",';
					place += '"website": "http://www.publicisnet.fr",';
					place += '"description": "a creative digital agency",';
					place += '"location": {';
					place += '	"street": "133 avenue des Champs-Elys\u00e9es",';
					place += '	"city": "Paris",';
					place += '	"country": "France",';
					place += '	"zip": "75008",';
					place += '	"latitude": 48.872984345,';
					place += '	"longitude": 2.296974235';
					place += '},';
					place += '"fan_count": 20';
					place += '}';
					
					var _FBPlace:FBPlace = new FBPlace(JSON.decode(place));
					_addMarker(_FBPlace);
					break;
			}
		}
		
		protected function _addMarker(place:FBPlace):void {
			var p:Point = place.position;
			var markerOptions : MarkerOptions = new MarkerOptions();
			markerOptions.tooltip = place.name;
			var marker:Marker = new Marker(new LatLng(p.x, p.y), markerOptions);
			map.addOverlay(marker);
		}
		
		protected function _initMap():void {
			map.key = "ABQIAAAA6_Oo7wXWwT2VijDEA1jUZhTEOwOs7NnDIuBu3AM48LjlYxnzXRRMJ6bFY8MRDxTOvhAJbxGhdY-0dg";
			map.setSize(new Point(500,400));
			map.sensor = "true";
			map.addEventListener(MapEvent.MAP_READY, _onMapReady);
			addChild(map);
		}
		
		protected function _onMapReady(e:MapEvent):void {
			addChildWithProps(new SimpleTextButton("place FBPlace"), { data:"place", click:onClick } );
		}
	}
}